package com.elinkway.infinitemovies.ui.fragment;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.elinkway.infinitemovies.adapter.UtilsFragmentPagerAdapter;
import com.elinkway.infinitemovies.view.PagerSlidingTabStrip;
import com.le123.ysdq.R;

/**
 * Created by zhaopeipei on 2016/9/1.
 */
public class UtilsFragment extends BaseFragment {

    public static String TAG = "ChannelFragment";

    private PagerSlidingTabStrip mTabs;

    private ViewPager mViewPager;

    private UtilsFragmentPagerAdapter utilsFragmentPagerAdapter;

    public static UtilsFragment newInstance(int position) {
        UtilsFragment fragment = new UtilsFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_utils, container, false);
        initViewPager(view);
        return view;
    }

    public void setTabs(PagerSlidingTabStrip tabs) {
        mTabs = tabs;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        super.setFragmentClassName(TAG);
        Log.i(TAG, "onAttach");
    }

    public void initViewPager(View view) {
        Rect frame = new Rect();
        getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        int actionBarHeight = getSupportActionBar().getHeight();
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        lp.setMargins(0, actionBarHeight, 0, 0);
        mViewPager = (ViewPager) view.findViewById(R.id.vp_utils_fragment_pager);
        mViewPager.setLayoutParams(lp);
        utilsFragmentPagerAdapter = new UtilsFragmentPagerAdapter(getFragmentManager(), getActivity());
        mViewPager.setAdapter(utilsFragmentPagerAdapter);
        if (mTabs != null) {
            mTabs.setTextColor(getResources().getColor(R.color.color_000000));
            mTabs.setDividerColorResource(R.color.white);
            mTabs.setTabPaddingLeftRight(getResources().getDimensionPixelOffset(R.dimen.len_25dp));
            mTabs.setIndicatorColorResource(R.color.white);
            mTabs.setTextSize(getResources().getDimensionPixelSize(R.dimen.font_18));
            mTabs.setBold(false);
            mTabs.setViewPager(mViewPager);
        }
    }

}
